//
//  EmoticonCell.m
//  微博表情键盘
//
//  Created by zxy on 2019/8/9.
//  Copyright © 2019 zxy. All rights reserved.
//

#import "EmoticonCell.h"
#import "XHHelper.h"
@implementation EmoticonCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _emoticonImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 32, 32)];
        _emoticonImageView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_emoticonImageView];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    _emoticonImageView.center =CGPointMake(self.width / 2, self.height / 2);
}

-(void)setModel:(XHEmoticon *)model{
    _model = model;
    if(_isDelete){
        _emoticonImageView.image = [XHHelper imageFromBundleName:@"ResourceWeibo" imageName:@"compose_emotion_delete"];
    }
   else{
        if(model.type == EmoticonTypeEmoji){//emoji表情
            NSNumber *num = [NSNumber numberWithString:model.code];
            NSString *str = [NSString stringWithUTF32Char:num.unsignedIntValue];
            NSLog(@"===%@",str);
            if(str){
                UIImage *img = [UIImage imageWithEmoji:str size:_emoticonImageView.bounds.size.width];
                _emoticonImageView.image = img;
            }
        }
        else{//图片表情
            _emoticonImageView.image = [XHHelper imageFromBundleName:@"EmoticonWeibo" imageName:model.png inDirectory:_groupID];
        }
    }
}

@end
